import router from './router'
import store from './store'
const whiteList = ['/login']
router.beforeEach(async (to, from, next) => {
  console.log('token', store.getters.token)
  if (store.getters.token) {
    if (to.path === '/login') {
      next('/')
    } else {
      console.log(22)
      console.log(!store.getters.userInfo)
      if (store.getters.userInfo) {
        await store.dispatch('user/getUserInfo')
      }
      next()
    }
  } else {
    if (whiteList.indexOf(to.path) === -1) {
      next('/login')
    } else {
      next()
    }
  }
})
